/*
* ventilation.c
* Compute the power required for ventilation (or unwanted air leaks)
* Assume the incomming air must be accellerated to the speed
* of the car and then deccellerated to 0 when leaving the car.
*
* This does not include the possible looses (or gains for a NACA duct) aerodynamics
* for the entire car, caused by the change in drag coef. (A * D_a)
*
* This should include driver ventilation, air intake in wheel openings, as well
* as leaks around body openings (between top and bottom etc...)
* A 0.5 CM gap on the front of the car (3M wide) is a 150 CM^2 hole
* giving 376 W of loss at 100.0 KM/H  !
*/
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include "ssm_conversions.h"

int main(int argc, char * argv[]) {

double rho = 1.17;    // density of air (KG/M^3)
double speed = -1.0;  // speed of car (M/S)
double hole  = -1.0;  // size of hole for ventilation (M^2)
double massps;        // mass per second of air taken in and out (KG/S)
double power;         // (W)
char   ch;            // used in sscanf() to check for extra characters.

if(argc!=3){
  fprintf(stderr, "ERROR 1: useage %s <speed Km/h> <hole cm^2>\n", argv[0]);
  exit(1);
}
if((sscanf(argv[1],"%lf%c",&speed,&ch)!=1) || (sscanf(argv[2],"%lf%c",&hole,&ch)!=1)) {
  fprintf(stderr, "ERROR 2: useage %s <speed Km/h> <hole cm^2>\n", argv[0]);
  exit(1);
}

hole = CUTOU * CUTOU * hole;
speed = KMPHTOMPS * speed;

massps = rho * hole * speed; // density (KG/M^3) * area (M^2) * legnth (M) / time (S)

// K_e = 0.5 * m v^2, both accellerate and decellerate
power = massps * speed * speed;  // (W = KG/S M/S M/S)

printf("power = %12.4f W\n", power);
exit(0);
}
